import logging
from redis import StrictRedis


class Config():
    """项目的配置"""
    DEBUG = True
    PORT = 8000

    # 配置密钥
    SECRET_KEY = 'akdjhlchoaubaojfhuahao;sfncjahciuf'

    # 为mysql添加配置
    SQLALCHEMY_DATABASE_URI = 'mysql://admin:password@127.0.0.1:3306/information'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 在请求结束时,如果指定配置为True,那么在请求结束的时候,会自动提交模型数据到数据库
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # Redis的配置
    REDIS_HOST = 'localhost'
    REDIS_PORT = 6379
    REDIS_DB = 1
    REDIS_PASSWORD = 'password'

    # Session保存配置
    SESSION_TYPE = 'redis'
    # 开启Session签名
    SESSION_USE_SIGNER = True
    # 指定Session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT,db=REDIS_DB,password=REDIS_PASSWORD)
    # 设置需要过期
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2

    # 设置默认的日志等级
    LOG_LEVEL = logging.DEBUG

class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True
    pass

class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = True
    LOG_LEVEL = logging.WARNING

class TestingConfig(Config):
    """单元测试环境下的配置"""
    DEBUG = True
    TESTING = True
    LOG_LEVEL = logging.WARNING

config = {
    'development':DevelopmentConfig,
    'production':ProductionConfig,
    'testing':TestingConfig
}
